package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.SignUpSetEntity;
import io.renren.modules.lanling.service.SignUpSetService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 报名公告设置表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-11-05 14:35:30
 */
@RestController
@RequestMapping("lanling/signupset")
public class SignUpSetController {
    @Autowired
    private SignUpSetService signUpSetService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:signupset:list")
    public R list(@RequestParam Map <String, Object> params) {
        PageUtils page = signUpSetService.queryPage( params );

        return R.ok().put( "page", page );
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:signupset:info")
    public R info(@PathVariable("id") Integer id) {
        SignUpSetEntity signUpSet = signUpSetService.selectById( id );

        return R.ok().put( "signUpSet", signUpSet );
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:signupset:save")
    public R save(@RequestBody SignUpSetEntity signUpSet) {
        signUpSet.setCreateDate( new Date() );

        signUpSetService.insert( signUpSet );
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:signupset:update")
    public R update(@RequestBody SignUpSetEntity signUpSet) {
        signUpSet.setLastModifyDate( new Date() );

        ValidatorUtils.validateEntity( signUpSet );
        signUpSetService.updateAllColumnById( signUpSet );//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:signupset:delete")
    public R delete(@RequestBody Integer[] ids) {
        signUpSetService.deleteBatchIds( Arrays.asList( ids ) );

        return R.ok();
    }

}
